package myky.com.doctorapp.adapter

import android.graphics.Color
import android.util.Log
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.facebook.drawee.view.SimpleDraweeView

import myky.com.doctorapp.R
import myky.com.doctorapp.entity.LongRangeListEntity
import myky.com.doctorapp.utils.UriUtils
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/8 on 14:24
 */
class RemoteListAdapter(data: List<LongRangeListEntity.PayLoadBean.ListBean>) : BaseQuickAdapter<LongRangeListEntity.PayLoadBean.ListBean, BaseViewHolder>(R.layout.remote_list_item, data) {

    override fun convert(helper: BaseViewHolder, item: LongRangeListEntity.PayLoadBean.ListBean) {
        //个人信息
        var header = helper.getView<SimpleDraweeView>(R.id.remote_list_item_header)
        header.setImageURI(UriUtils.getUriInstance().getUri(item.doctor.headPhoto))
        helper.setText(R.id.remote_list_item_tv1,item.doctor.realname)
        helper.setText(R.id.remote_list_item_tv2,item.doctor.departmentname)
        helper.setText(R.id.remote_list_item_tv4,item.description)
        helper.setText(R.id.remote_list_item_tv5,item.createtime)
        //状态view
        val statusTv = helper.getView<TextView>(R.id.remote_list_item_tv3)
        val speText = helper.getView<TextView>(R.id.remote_list_item_tv6)
        val currStatus = item.currStatus
        var array = mContext.resources.getStringArray(R.array.remote_status)
        speText.visibility= View.GONE
        statusTv.setTextColor(Color.parseColor("#ff822e"))
        when(currStatus){


            1->{
               statusTv.text=array[0]
            }
            2->{
                statusTv.text=array[3]
            }
            3->{
                statusTv.text=array[3]
            }
            4->{
                statusTv.text=array[5]
            }
            5->{
                statusTv.text=array[5]
                speText.text=array[6]
                speText.visibility= View.VISIBLE
                speText.setBackgroundResource(R.drawable.wdyc_bczl)
            }
            6->{
                statusTv.text=array[5]
                speText.text=array[7]
                speText.visibility= View.VISIBLE
                speText.setBackgroundResource(R.drawable.wdyc_ybczl)
            }
            7->{
                statusTv.text=array[2]
            }
            8->{
                var time = getRandomTime(item.updatetime)
                if(time==null){
                statusTv.text=array[9]
                statusTv.setTextColor(Color.parseColor("#00c934"))

                }else{
                statusTv.text=array[1]
                }
            }
            9->{
                statusTv.text=array[10]
            }



        }
        helper.addOnClickListener(R.id.remote_list_item_lin1)
    }

    /**
     * 开方中和正在开方中本地时间比较5分钟变成已开方
     */
    fun getRandomTime(time: String): String? {


        var backTime: String? = null
        val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        try {
            val createTime = dateFormat.parse(time)
            val currentTime = Date(System.currentTimeMillis())
            val diff = currentTime.time - createTime.time
            Log.i("out", "时间差...$diff")

            if (diff > 300000) {
                backTime = dateFormat.format(Date(createTime.time + 300000))

            }
        } catch (e: ParseException) {
            e.printStackTrace()

        }


        return backTime
    }
}
